﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using School.Entities;
using System.Collections;
using System.IO;


namespace School.Admission
{
    public class Mother
    {
        private static SchoolEntities db = new SchoolEntities();

        public static Boolean Add( SD_Mother   mother)
        {
            try
            {
                db.AddToSD_Mother(mother);
                db.SaveChanges();

                return true;
            }

            catch
            {
                return false;

            }
        }

        public static SD_Mother Single(long id)
        {
            return db.SD_Mother.Single(x => x.Id == id);
        }


        public static SD_Mother SingleByStudentId(long sid)
        {
            try
            {
                return db.SD_Mother.Single(x => x.Student_Id == sid);

            }
            catch
            {
                return null;
            }


        }



        public static IEnumerable<SD_Mother> All(Hashtable items)
        {
            SchoolEntities db = new SchoolEntities();

            var query = from mother in db.SD_Mother select mother;

            foreach (DictionaryEntry item in items)
            {
                if (item.Key == "Ar_FirstName")
                {
                    query = query.Where(c => c.Ar_FirstName == item.Value);
                }

                if (item.Key == "Ar_SecondName")
                {
                    query = query.Where(c => c.Ar_SecondName == item.Value);
                }

                if (item.Key == "Ar_ThirdName")
                {
                    query = query.Where(c => c.Ar_ThirdName == item.Value);
                }


                if (item.Key == "Ar_FourthName")
                {
                    query = query.Where(c => c.Ar_FourthName == item.Value);
                }


            }
            return query.ToList();
        }

        public static void Update(SD_Mother mother)
        {
            SD_Mother c = db.SD_Mother.Single(x => x.Id == mother.Id);


            c.Id = mother.Id;
            c.Student_Id = mother.Student_Id;

            c.Ar_FirstName = mother.Ar_FirstName;
            c.Ar_SecondName = mother.Ar_SecondName;
            c.Ar_ThirdName = mother.Ar_ThirdName;
            c.Ar_FourthName = mother.Ar_FourthName;

            c.En_FirstName = mother.En_FirstName;
            c.En_SecondName = mother.En_SecondName;
            c.En_ThirdName = mother.En_ThirdName;
            c.En_FourthName = mother.En_FourthName;

            c.Gregorian_BirthDate = mother.Gregorian_BirthDate;
            c.Hijri_BirthDate = mother.Hijri_BirthDate;
            c.Identification_Number = mother.Identification_Number;
            c.Pasport_Number = mother.Pasport_Number;
            c.Qualification_Id = mother.Qualification_Id;
            c.Specialization = mother.Specialization;
            c.PointOfGraduation = mother.PointOfGraduation;
            c.Greggorian_GraduationDate = mother.Greggorian_GraduationDate;
            c.Hijri_GraduationDate = mother.Hijri_GraduationDate;
            c.HomeAddress_Id = c.HomeAddress_Id;
            c.WorkAddress_Id = mother.WorkAddress_Id;
            c.Nationality_Id = mother.Nationality_Id;

            db.SaveChanges();

        }

        public static Boolean Delete(long id)
        {
            try
            {
                db.SD_Mother.DeleteObject(db.SD_Mother.Single(x => x.Id == id));
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

    }
}
